package com.wht.bill.utils;


import android.app.Dialog;
import android.content.Context;
import android.view.Gravity;
import android.view.View;
import android.view.ViewGroup;
import android.view.Window;
import android.view.WindowManager;

import com.wht.bill.R;

public class DialogUtil {
    public interface onConfirmClickListener {
        void onConfirmClick();
    }

    public static void showDeleteDialog(Context context, final onConfirmClickListener v) {
        final Dialog dialog = new Dialog(context, R.style.dialog);
        dialog.setContentView(R.layout.dialog_delete);
        dialog.setCancelable(true);
        dialog.setCanceledOnTouchOutside(true);
        dialog.findViewById(R.id.btn_confirm).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                v.onConfirmClick();
                dialog.dismiss();
            }
        });
        dialog.findViewById(R.id.btn_cancel).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                dialog.dismiss();
            }
        });
        dialog.show();

        Window dialogWindow = dialog.getWindow();
        //设置dialog位置
        WindowManager.LayoutParams params = dialogWindow.getAttributes();
        params.height = ViewGroup.LayoutParams.WRAP_CONTENT;
        params.width = ViewGroup.LayoutParams.MATCH_PARENT;
        dialogWindow.setAttributes(params);
        dialogWindow.setGravity(Gravity.CENTER);
    }
}
